﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BusinessObjects.BO_GetObjects;
using System.IO;
using DigiLib;

public partial class Administrator_Controls_AdminModulesAdd : Admin_Controls_Base {
    protected void Page_Load(object sender, EventArgs e) {
        base.removeHGC(divMessage);
        if (!IsPostBack) {
            base.bindDDL(ddlParentMenu, BO_cms_admin_modules.Inside(0), "DESCRIPTION", "ADMIN_MODULE_ID");
            txtSortDisplay.Text = SqlUtils.GetNextOrderDisplay("cms_admin_modules").ToString();
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e) {
        try {
            string desc = txtDesc.Text.Trim();
            int od = Convert.ToInt32(txtSortDisplay.Text.Trim());
            string menuname = txtMenuName.Text.Trim();
            DataTable objDT = (DataTable)Session["admin"];
            bool cp = cboCP.Checked;
            string cp_thumb_icon = string.Empty;
            if (cp) cp_thumb_icon = base.Upload("cpIcon", string.Empty, fulIcon, divMessage, true);
            string thumb_icon = base.Upload("cpIcon", string.Empty, fupThumbIcon, divMessage, true);
            string strResult = BO_cms_admin_modules.Insert(Convert.ToInt32(ddlParentMenu.SelectedValue),
                menuname,
               thumb_icon, cp_thumb_icon, desc,
                cboDisOnHome.Checked, cp,
                od, DateTime.Now, Administrator.USER_NAME,
                DateTime.Now,
                Administrator.USER_NAME,
                true);
            if (strResult != "0")
                divMessage.InnerHtml = MessageBox.Success("Hệ Thống", "Thêm mới menu hệ thống thành công!");
            else
                divMessage.InnerHtml = MessageBox.Error("Hệ Thống", "Có lỗi trong quá trình xử lý, thử lại sau!");
            base.Clear(this.Controls);
        } catch (Exception ex) {
            divMessage.InnerHtml = MessageBox.Error("Lỗi", "Phát hiện lỗi xảy ra !<br />" + ex.Message);
        }
    }
}
